package classes
{
	import mx.formatters.DateBase;
	import classes.Account;
	import classes.TreasuryModel;
	import classes.Transaction;
	import classes.User;

	
	public class viewHistoryBudget
	{
		public var month:String = " ";
		public var amountDefined:Number = 0.00;
		public var amountUsed:Number;
		public var amountLeftOver:Number;
		
		public function viewHistoryBudget()
		{
			month = "sdfhg ";
		 amountDefined = 0.00;
		 amountUsed = 355;
		 amountLeftOver = 2345;
		
		}
		
		public function calculateAmountUsed( category:String, month:Number, year:Number):Number{
			var amoUsed:Number = 0;
			var i = 0;
			for(; i< (TreasuryModel.getInstance().currentUser.accounts.length); i++){
				// this loop goes through every regular transaction that was made in that account.
				var currentAccount:Account = TreasuryModel.getInstance().currentUser.accounts.getItemAt(i) as Account;
				var j = 0;
				for (; j<(currentAccount.transactions.length); j++){
					// go through every transaction and check if it was made in the current month
					var currentTransaction: Transaction = currentAccount.transactions.getItemAt(j) as Transaction;
					
					if (currentTransaction.category.toUpperCase() == category.toUpperCase()){
						if (currentTransaction.date.getMonth() == month && currentTransaction.date.fullYear == year){
							amoUsed = amoUsed + currentTransaction.amount;
						}
					}
					currentTransaction = null;
				}
			
			}
			return amoUsed;
		
		}
		
		public function findMonth(currentMonth:Number):String{
			var m:String = " ";
			if (currentMonth == 0)
			{ m = "January" as String}
			else if (currentMonth == 1)
			{ m= "February" as String}
			else if (currentMonth == 2)
			{ m = "March" as String}
			else if (currentMonth == 3)
			{ m = "April" as String}
			else if (currentMonth == 4)
			{ m = "May" as String}
			else if (currentMonth == 5)
			{ m = "June" as String}
			else if (currentMonth == 6)
			{ m = "July" as String}
			else if (currentMonth == 7)
			{ m = "August" as String}
			else if (currentMonth == 8)
			{ m = "September" as String}
			else if (currentMonth == 9)
			{ m = "October" as String}
			else if (currentMonth == 10)
			{ m = "November" as String}
			else if (currentMonth == 11)
			{ m = "December" as String}
			else{
				m = "Month Not found" as String;
			}
			return m as String;
		}
}
}